<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<div class="modal-dialog x-modal-dialog" style="width: 650px; margin-top: 100px;">

  <div class="modal-content">
  
    <div class="modal-header x-breadcrumb no-bottom-border clearfix">
      <h2><i class="glyphicon glyphicon-fire" title="电话资源"></i>&nbsp;&nbsp;<span>电话资源列表&nbsp;-&nbsp;修改电话资源</span></h2>
      <button type="button" class="close" data-dismiss="modal">&times;</button>
    </div>
    
    <form class="form-horizontal" method="POST" action="${ctx.host}/telephone-resources/${telephoneResource.id}/edit" data-validate="true">
      <input type="hidden" name="_method" value="PATCH">
      <input type="hidden" name="id" value="${telephoneResource.id}" />

      <div class="modal-body">
        <div class="form-group x-form-group">
          <label class="col-xs-4 control-label">门店</label>
          <div class="col-xs-6 pull-left">
            <c:choose>
              <c:when test="${currentPrincipal.siteManager or currentPrincipal.siteServer}">
                <p class="form-control-static">${currentPrincipal.site.name}</p>
                <input type="hidden" name="site" value="${currentPrincipal.site.id}">
              </c:when>
              <c:otherwise>
                <select name="site" class="select2 form-control" data-validate="required">
                  <option value=""></option>
                  <c:forEach var="site" items="${persist.getSites(currentPrincipal.id)}">
                    <c:if test="${!site.disabled}">
                      <option value="${site.id}" ${telephoneResource.site.id eq site.id ? 'selected' : ''}>${site.name}</option>
                    </c:if>
                  </c:forEach>
                </select>
              </c:otherwise>
            </c:choose>
          </div>
        </div>
        
        <div class="form-group x-form-group">
          <label class="col-xs-4 control-label">首次接待人</label>
          <div class="col-xs-6 pull-left">
             <select name="receptionist" class="select2 form-control" data-validate="required">
              <option value=""></option>
              <c:forEach var="staff" items="${persist.staff(currentPrincipal.id)}">
                <option value="${staff.id}" ${telephoneResource.receptionist.id eq staff.id ? 'selected' : ''}>${staff.name}</option>
              </c:forEach>
            </select>
          </div>
        </div>
        
        <div class="form-group x-form-group">
          <label class="col-xs-4 control-label">渠道</label>
          <div class="col-xs-6 pull-left">
            <input type="text" class="form-control" name="channel" value="${telephoneResource.channel}" data-validate="required" placeholder="请输入渠道"/>
          </div>
        </div>
        
        <div class="form-group x-form-group">
          <label class="col-xs-4 control-label">名单收集日期</label>
          <div class="col-xs-6 pull-left">
            <input type="text" class="form-control date" name="collectDate" value="<fmt:formatDate type='date' value='${telephoneResource.collectDate}' />" data-validate="required" placeholder="请输入名单收集日期"/>
          </div>
        </div>
        
        <div class="form-group x-form-group">
          <label class="col-xs-4 control-label">是否到店</label>
          <div class="col-xs-6 pull-left">
            <select name="experienced" class="select2 form-control" data-validate="required">
              <option value="false" ${telephoneResource.experienced ? '' : 'selected'}>否</option>
              <option value="true" ${telephoneResource.experienced ? 'selected' : ''}>是</option>
            </select>
          </div>
        </div>
        
        <div class="form-group x-form-group">
          <label class="col-xs-4 control-label">未到店原因</label>
          <div class="col-xs-6 pull-left">
            <textarea rows="3" class="form-control" name="breakReason">${telephoneResource.breakReason}</textarea>
          </div>
        </div>
      </div>

      <div class="modal-footer">
        <button type="submit" class="btn btn-success btn-shadow btn-shadow-success x-btn">确定</button>&nbsp;&nbsp;&nbsp;&nbsp;
        <button type="button" class="btn btn-default btn-shadow btn-shadow-default x-btn" data-dismiss="modal">取消</button>
      </div>
    </form>
  </div>
</div>

<script type="text/javascript">
  $(function() {
    $('select[name="experienced"]').select2({
        placeholder : '请选择是否到店',
        minimumResultsForSearch : -1,
        allowClear : true,
        width: '100%'
      });
    
    $('select[name="site"]').select2({
        placeholder : '请选择门店',
        minimumResultsForSearch : -1,
        allowClear : true,
        width: '100%'
      });
    
    $('select[name="receptionist"]').select2({
        placeholder : '请选择首次接待人',
        minimumResultsForSearch : -1,
        allowClear : true,
        width: '100%'
      });
  })
</script>